# Loads random library, time library and math library
import random
import time
import math

# Begin the GenericGuard Class, which is the base class for nonspecial guards and is inherited to guard subtypes
class GenericGuard(pygame.sprite.Sprite):
  def __init__(self, training, health, weapon, ammo, image, x, y, width, height):
      # Sets game mechanics for guard
      self.rect       = ((x, y), (width, height))
      self.image      = image

      # Sets the initial flags of the guard  
      self.guard_type = training
      self.health     = health
      self.weapon     = weapon
      self.ammo       = ammo
  
  # This creates a triangle to find the tangent, which is the angle from the guard to the player  
  def getTangent(self.firepoint_x, self.firepoint_y):                                    
      # This sets the co-ordinates of target that the Guard is aiming at
      player_target_x = getTarget(guard_type)
      player_target_y = getTarget(guard_type)
      # Calculates the x and y distances of the player, and uses their hit normals as the right angle
      adjacent        = math.abs(self.firepoint_x - player_target_x)
      opposite        = math.abs(self.firepoint_y - player_target_y) 
      # Works out the Tangent and converts it to degrees.
      tangent         = math.degrees(tan(opposite/adjacent))
      # Returns the tangent variable
      return tangent

  def guardFire:
      # This assigns self.accuracy the getAccuracy class, which will call the accuracy stat from the guard's skill list   
      self.accuracy   = getAccuracy()                                                   
      # Finds the angle to aim at  
      aim_angle       = getTangent()                                                        
      # Calculates the factor by which the Guard will miss. 0 if perfectly accurate  
      shot_angle      = (randint(self.accuracy / 2.0, 100 - (self.accuracy / 2.0))) - 50  
      shot_angle      = ((aim_angle * miss_factor) / 100.0) + aim_angle

      if shot_angle > 180:                                                    
          shot_angle -= shot_angle - 180
  
  if fire_again == true:
      time.sleep(random.randint(2,5))
      guardFire() 
